package com.speljohan.rsbot.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Stroke;

import javax.swing.Icon;

public class SimpleIcon implements Icon {
	private final Color color;
	private final int height;
	private final Stroke stroke;
	private final int width;

	/**
	 * If stroke is null it will draw a rectangle with a border. Otherwise a
	 * cross.
	 * */
	public SimpleIcon(final int height, final int width, final Color color,
			final Stroke stroke) {
		this.height = height;
		this.width = width;
		this.color = color;
		this.stroke = stroke;
	}

	public int getIconHeight() {
		return height;
	}

	public int getIconWidth() {
		return width;
	}

	public void paintIcon(final Component c, final Graphics g, final int x,
			final int y) {
		final Graphics2D g2d = (Graphics2D) g.create();
		g2d.setColor(color);
		if (stroke == null) {
			g2d.fillRect(x, y, width, height);
			g2d.setColor(Color.BLACK);
			g2d.drawRect(x, y, width, height);
		} else {
			g2d.setStroke(stroke);
			g2d.drawLine(x, y, x + width, y + height);
			g2d.drawLine(x + width, y, x, y + height);
		}
	}
}
